using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace BuddhistSchools.DTO.Models.Mapping
{
    public class FunctionMap : EntityTypeConfiguration<Function>
    {
        public FunctionMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Name)
                .HasMaxLength(50);

            this.Property(t => t.FunctionName)
                .IsRequired()
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("Function");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.FunctionName).HasColumnName("FunctionName");

            // Relationships
            this.HasMany(t => t.Roles)
                .WithMany(t => t.Functions)
                .Map(m =>
                    {
                        m.ToTable("Role_Function");
                        m.MapLeftKey("FunctionID");
                        m.MapRightKey("RoleID");
                    });


        }
    }
}
